#ifndef CLIENT_H
#define CLIENT_H

#include <string>
#include <list>
#include <boost/serialization/list.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/nvp.hpp>
#include "../Config.h"

class TCPConnection;

class ClientCategory
{
public:
  ClientCategory() { }
  ~ClientCategory() { }
  ClientCategory(std::string &login, std::string &category)
  {
    _login = login;
    _category = category;
  }
  std::string &getLogin() { return _login; }
  std::string &getCategory() { return _category; }
  void setLogin(std::string &login) { _login = login; }
  void setCategory(std::string &cat) { _category = cat; }
private:
  std::string _login;
  std::string _category;

  friend class boost::serialization::access;
  template<class archive>
  void serialize(archive& ar, const unsigned int version)
  {
    using boost::serialization::make_nvp;
    ar & make_nvp("Login", _login);
    ar & make_nvp("Category", _category);
  }
};

class Client
{
public:
  enum eClientStatus
    {
      online,
      offline
    };
  Client() { }
  ~Client() { }
  void save(const std::string &filename);
  void save() { save(getFilename()); }
  static Client *load(const std::string &filename);
  void setLogin(const std::string &login) { _login = login; }
  void setPassword(const std::string &password) { _password = password; }
  void setMail(const std::string &mail) { _mail = mail; }
  bool friendsExist(const std::string &login);
  void addFriends(ClientCategory *friends)
  {
    if (friendsExist(friends->getLogin()))
	return;
    _friends.push_back(friends);
    save();
  }
  void removeFriends(const std::string &friends);
  std::string &getLogin() { return _login; }
  std::string &getPseudo() { return _pseudo; }
  std::string &getPass() { return _password; }
  void setStatus(const eClientStatus status) { _status = status; }
  std::string &getIp() { return _ip; }
  void setAge(const int age) { _age = age; }
  int getAge() const { return _age; }
  void setIp(const std::string &ip) { _ip = ip; }
  void setPseudo(const std::string &pseudo) { _pseudo = pseudo; }
  void setConnexion(TCPConnection *con) { _connexion = con; }
  TCPConnection *getConnexion() const { return _connexion; }
  std::list<ClientCategory*> &getFriends() { return _friends; }
  std::string getFilename() { return PATH_DATAS + this->getLogin() + ".txt"; };
private:
  std::string _login;
  std::string _password;
  std::string _mail;
  std::string _pseudo;
  int _age;
  std::list<ClientCategory*> _friends;
  eClientStatus _status;
  std::string _ip;
  TCPConnection *_connexion;

  friend class boost::serialization::access;
  template<class archive>
  void serialize(archive& ar, const unsigned int version)
  {
    using boost::serialization::make_nvp;
    ar & make_nvp("Login", _login);
    ar & make_nvp("Password", _password);
    ar & make_nvp("Mail", _mail);
    ar & make_nvp("Age", _age);
    ar & make_nvp("Pseudo", _pseudo);
    ar & make_nvp("Friends", _friends);
  }

};

#endif
